package org.gd.spring.batis;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import org.gd.hellojaxb.utils.Marshall;
import org.gd.hellojaxb.utils.MarshallProperties;

/**
 * <a href="http://howtodoinjava.com/2013/01/03/ibatis-hello-world-example-with-source-code/"></a>
 */
public class TestMain {

    public static void main(String[] args) throws Exception {

        UserDao manager = new UserDaoIbatis();

        SqlMapClient sqlmapClient = SqlMapClientBuilder.buildSqlMapClient(
                TestMain.class.getClassLoader().getResourceAsStream("batis/sql-maps-config.xml"));

        manager.addUser(new UserTEO()
                .setId(1)
                .setName("Demo User")
                .setPassword("password")
                .setEmail("demo-user@howtodoinjava.com")
                .setStatus(1),
                sqlmapClient);

        UserTEO createdUser = manager.getUserById(1, sqlmapClient);
        System.out.println(Marshall.getInstance().marshal(createdUser, MarshallProperties.FORMATTED_OUTPUT));

        manager.deleteUserById(1, sqlmapClient);
    }
}
